<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象式写法--自定义指令</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <!-- 实现输入框一上来就聚焦 -->
    <div id="app">
        <input type="text" v-fbind:value="n"/>
        <button @click="add">+1</button>
    </div>
    <script>
        const vm = new Vue({
            el:'#app',
            data:{
                n:1
            },
            methods:{
                add(){
                    this.n++
                }
            },
            directives:{
                fbind:{
                    // 指令与标签成功绑定
                    bind(ele,binging){
                        ele.value = binging.value;
                    },
                    // 绑定成功后插入页面时
                    inserted(ele,binging){
                        ele.focus()
                    },
                    // 模板重新渲染时
                    update(ele,binging){
                        ele.value = binging.value;
                    }
                }
            }
        })
    </script>
</body>
</html>